<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE HTML>
<html>
<head>

<%@ include file="/common/meta.jsp"%>
<%@ include file="/common/links.jsp"%>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Insert title here</title>
   <script type="text/javascript">
   var formOptions = {
			dataType : "json",
			beforeSubmit : processBeforeSubmit, // pre-submit callback
			success : processResponseAfterSubmit//,
		};
	function processResponseAfterSubmit(data,status,xhr,jqform) {
		try {
			if (data.ajaxStatus === "success") {
				var m = parent.parent.jQuery.ligerDialog.tip({  title: '提示信息',content:data.ajaxMessage});
				setTimeout(function (){m.hide();}, 5000);
				//window.parent.$.ligerDialog.unmask();
				window.parent.$.ligerDialog.close();
				window.parent.grid.loadData(); 


			} else {

				if ( data.fieldErrors != null && data.fieldErrors.length !== 0 ) {
					$.each(data.fieldErrors, function(e) {
						$("[name$='"+e+"']").validationEngine('showPrompt', data.fieldErrors[e], 'error','centerRight', true);
						//能自动聚焦到就好了
						$("[name$='"+e+"']").focus()
					});
				}else{
				 $.ligerDialog.error(data.ajaxMessage);
				}
			}
		} catch (e) {
			alert(e.message);
		}
	}
	function processBeforeSubmit(formData, jqForm, options) {
		var v = jqForm.validationEngine('validate');
		if (v) {
			return true
		} else {
			return false;
		}
	}
        $(function ()
        {
            $("#demoEntity_timestampField").ligerDateEditor({ showTime: true });
            $("form").ligerForm();
            $('#submit').click(function() {
    			try{
    			var subResult = $('#entityForm').ajaxSubmit(formOptions);
    			return false;
    			}catch(e){
    				alert(e.message);
    			}
    		})
    		$('#cancel').click(function() {
    			//alert("cancel")
    			window.parent.$.ligerDialog.close();
    			//parent.jQuery.colorbox.close();//这句话是需要的。
    		})
    		 jQuery("#entityForm").validationEngine({promptPosition : "centerRight"});
        });
    </script>
    <style type="text/css">
           body{ font-size:12px;}
        .l-table-edit {}
        .l-table-edit-td{ padding:4px;}
        .l-button-submit,.l-button-reset{width:80px; float:left; margin-left:10px; padding-bottom:2px;}
        .l-verify-tip{ left:230px; top:120px;}
    </style>
</head>
<body>
<s:form id="entityForm" action="saveEntity" >
			<s:hidden name="gridId"/>
			<s:hidden name="editType"/>
			<s:textfield key="demoEntity.demoId" name="model.demoId" />
			<s:textfield key="demoEntity.intField" name="model.intField" ltype='spinner' ligerui="{type:'int'}" cssClass="validate[required,custom[integer]]"/>
			<s:textfield key="demoEntity.longField" name="model.longField" cssClass="validate[required,custom[integer]]"/>
			<s:textfield key="demoEntity.shortField" name="model.shortField" />
			<s:textfield key="demoEntity.byteField" name="model.byteField" />
			<s:checkbox key="demoEntity.booleanField" name="model.booleanField" />
			<s:textfield key="demoEntity.charField" name="model.charField" />
			<s:textfield key="demoEntity.floatField" name="model.floatField" cssClass="validate[required,custom[number]]">
			<s:param name="value"><s:number name="model.floatField" type="number" /></s:param>
			</s:textfield>
			<s:textfield id="demoEntity_doubleField" key="demoEntity.doubleField" name="model.doubleField" cssClass="validate[required,custom[number]]" required="true"/>
			<s:textfield key="demoEntity.intObjField" name="model.intObjField" cssClass="validate[required,custom[integer]]"/>
			<s:textfield key="demoEntity.longObjField" name="model.longObjField" cssClass="validate[required,custom[integer]]"/>
			<s:textfield key="demoEntity.shortObjField"
				name="model.shortObjField" />
			<s:textfield key="demoEntity.byteObjField" name="model.byteObjField" />
			<s:checkbox key="demoEntity.booleanObjField"
				name="model.booleanObjField" />
			<s:textfield key="demoEntity.charObjField" name="model.charObjField" />
			<s:textfield key="demoEntity.floatObjField"
				name="model.floatObjField" />
			<s:textfield key="demoEntity.doubleObjField"
				name="model.doubleObjField" />
			<s:textfield id="demoEntity_dateField" key="demoEntity.dateField" name="model.dateField" ltype="date" cssClass="validate[required,custom[date]]">
				<s:param name="value"><s:date name="model.dateField" format="%{getText('date.format')}"/></s:param>
			</s:textfield>
			<s:textfield key="demoEntity.stringField" name="model.stringField" />
			<s:textfield key="demoEntity.bigDecimalField"
				name="model.bigDecimalField" />
			<s:textfield id="demoEntity_timestampField" key="demoEntity.timestampField" 	name="model.timestampField" >
				<s:param name="value"><s:date name="model.timestampField" format="%{getText('timestamp.format')}"/></s:param>
			</s:textfield>

		</s:form>
			<button name="submit" type="button" id="submit" class="btn">
			<s:text name="button.save" />
		</button>
		<button name="cancel" type="button" id="cancel" class="btn">
			<s:text name="button.cancel" />
		</button>
</body>
</html>